let pic = "./imgs/food.jpg"

let vm = new Vue({
    el: '#app',
    data: {
        list: [
            { name: '麻辣米线', price: 13, pic, count: 1 },
            {name:'大闸蟹',price:666,pic,count:1},
            {name:'大鲤鱼',price:99,pic,count:1},
            
        ]
    },
    methods: {
        add(item) {
            item.count++;
        },
        sub(item) {
            if (item.count > 0) item.count--;
        },
        clean() {
            this.list = [];
        }
    },
    computed: {
        totalCount(){
            var sum = 0;
            this.list.forEach((item)=>{
                sum += item.count;
            })
            return sum;
        },
        totalPrice: {
            get(){
                var sum = 0;
                this.list.forEach((item)=>{
                    sum += item.count * item.price;
                })
                return sum;
            },
            set(){ 
                console.log( '给totalPrice设置值' );
            }
        }
    },
})